<?php

declare(strict_types=1);
/**
 * This file is part of Hyperf.
 *
 * @link     https://www.hyperf.io
 * @document https://doc.hyperf.io
 * @contact  group@hyperf.io
 * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
 */
namespace Swb\Shop\Model;

use Hyperf\Cache\Annotation\Cacheable;
use Hyperf\DbConnection\Db;
use Hyperf\Database\Model\Events\Creating;
use Hyperf\Database\Model\Events\Updating;
use Hyperf\DbConnection\Model\Model as BaseModel;
use Hyperf\Utils\Context;

/**
 * @property int $id
 * @property string $name
 * @property string $province_name
 * @property int $province_id
 * @property string $city_name
 * @property int $city_id
 * @property string $area_name 区--回显
 * @property int $area_id
 * @property string $create_by 创建人
 * @property \Carbon\Carbon $created_at 创建时间
 * @property string $update_by 修改人
 * @property \Carbon\Carbon $updated_at 更新时间
 * @property int $del_flag
 */
class SysBusinessArea extends BaseModel
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'sys_business_areas';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = ['name', 'province_name', 'province_id', 'city_name', 'city_id', 'area_name', 'area_id'];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = ['id' => 'integer', 'province_id' => 'integer', 'city_id' => 'integer', 'area_id' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime', 'del_flag' => 'integer'];

    public function create_user()
    {
        return $this->hasOne(SysUser::class, 'create_by');
    }

    public function creating(Creating $event)
    {
        $this->create_by = Context::get('uid');
    }

    public function updating(Updating $event)
    {
        $this->update_by = Context::get('uid');
    }
}
